package com.chucang.shucang.common.security.entity;

import lombok.Getter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * @author flitsneak
 * @email flitsneak@gmail.com
 * @date 2022/9/16 15:15
 * @description 增强安全用户信息
 */
public class ShuCangUser extends User implements OAuth2AuthenticatedPrincipal {

    /**
     * 用户id
     */
    @Getter
    private final Long id;
    /**
     * 手机号
     */
    @Getter
    private final String cellPhoneNum;
    /**
     * 真实用户名
     */
    @Getter
    private final String realUserName;
    /**
     * 是否实名认证
     */
    @Getter
    private final Integer isRealAuth;
    /**
     * 链账户地址
     */
    @Getter
    private final String offshoreAccount;

    public ShuCangUser(Long id, String username, String password, String cellPhoneNum, String realUserName, Integer isRealAuth, String offshoreAccount, boolean enabled,
                       boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked,
                       Collection<? extends GrantedAuthority> authorities) {
        super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
        this.id = id;
        this.cellPhoneNum = cellPhoneNum;
        this.realUserName = realUserName;
        this.isRealAuth = isRealAuth;
        this.offshoreAccount = offshoreAccount;
    }

    /**
     * Get the OAuth 2.0 token attributes
     *
     * @return the OAuth 2.0 token attributes
     */
    @Override
    public Map<String, Object> getAttributes() {
        return new HashMap<>();
    }

    @Override
    public String getName() {
        return this.getUsername();
    }

    @Override
    public boolean equals(Object obj) {
        return super.equals(obj);
    }

    @Override
    public int hashCode() {
        return super.hashCode();
    }
}
